﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace PixentrationEngine
{
    class Program
    {
       
        /* 
         * 
         * This program is intended to be run several times 
         * with several different versions of the data file.  
         * 
         * 1.  A data file that contains 10 "real" entries.
         * 2.  A data file that is missing at least one entry.
         * 3.  A data file that contains invalid entries:
         *      a.  An empty line
         *      b.  An entry with a missing comma
         *      c.  An entry with no data between two commas.
         *  4.  A data file that does not exist.    
         * 
         */

        public static void Main(string[] args)
        {

            Scorecard sc = new Scorecard();

            String logFilePath = sc.FILE_PATH;
            String logFileName = "BBTestLog.txt";
            String logFile = logFilePath + "\\" + logFileName;

            if (File.Exists(logFile))
            {
                File.Delete(logFile);
            }

            using (StreamWriter logWriter = new StreamWriter(File.Create(logFile)))
            {

                logWriter.WriteLine("BLACK-BOX TEST CASES");
                logWriter.WriteLine("====================");
                logWriter.WriteLine();

                logWriter.WriteLine("Creation Date:  " + DateTime.Now);
                logWriter.WriteLine();
                logWriter.WriteLine();

                logWriter.WriteLine("Creating new Scorecard object...");

                logWriter.WriteLine("File: " + sc.TARGET);
                logWriter.WriteLine();


                logWriter.WriteLine("Loading scores into Scorecard object...");
                sc.LoadScores();

                List<ScoreEntry> test = sc.GetScores();
                logWriter.WriteLine();
                logWriter.WriteLine("List returned by sc.GetScores()");
                foreach (ScoreEntry se in test)
                    logWriter.WriteLine(se);


                ScoreEntry[] entries = new ScoreEntry[4];
                entries[0] = new ScoreEntry("ABC", 54321);
                entries[1] = new ScoreEntry("DEF", 8675309);
                entries[2] = new ScoreEntry("GHI", 93123);
                entries[3] = new ScoreEntry("JKL", 100000);

                foreach (ScoreEntry s in entries)
                {
                    if (sc.NewScore(s))
                    {
                        logWriter.WriteLine();
                        logWriter.WriteLine("New high score:  " + s);
                    }
                }

                logWriter.WriteLine();
                logWriter.WriteLine();
                logWriter.WriteLine("Updated scoreboard");
                foreach (ScoreEntry s in sc.scores)
                {
                    logWriter.WriteLine(s);
                }

                logWriter.WriteLine();
                logWriter.WriteLine();
                logWriter.Write("Deleting data file to confirm that a ");
                logWriter.WriteLine("new file will be created...");
                File.Delete(@"C:\ProgramData\Pixentration\highscores.txt");

                logWriter.WriteLine("\n\nSaving scores...\n");
                sc.SaveScores();

                logWriter.WriteLine();
                logWriter.WriteLine();
                logWriter.WriteLine("Updated scoreboard");
                foreach (ScoreEntry s in sc.scores)
                {
                    logWriter.WriteLine(s);
                }

            }

        }
    }
}
